package com.iplant.wms.controller.bill;

import com.iplant.base.po.ServiceResult;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.basic.controller.BasicController;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.wms.service.WMSService;
import com.iplant.wms.service.po.bill.WMSSalesDeliveryItem;
import com.iplant.wms.service.po.wms.WMSStockRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author PengYouWang
 * 2022-9-19 21:27:05
 */
@RestController
@RequestMapping("/api/WMSSalesDeliveryItem")
public class WMSSalesDeliveryItemController extends BasicController<WMSSalesDeliveryItem> {
    private static final Logger logger = LoggerFactory.getLogger(WMSSalesDeliveryItemController.class);

    @Autowired
    WMSService wWMSService;

    public WMSSalesDeliveryItemController( ) {
        super(WMSSalesDeliveryItem.class);

    }




    /**
     * 根据发货单子项ID查询库存信息
     */
    @GetMapping("/QueryStockInfoByItemID")
    public Object QueryStockInfoByItemID(HttpServletRequest request) {
        Object wResult;
        try {
            BMSEmployee wLoginUser = GetSession(request);

            // 获取参数
            int wSalesDeliveryItemID = StringUtils.parseInt(request.getParameter("SalesDeliveryItemID"));

            if (wSalesDeliveryItemID <= 0) {
                return GetResult(RetCode.SERVER_CODE_ERR, RetCode.SERVER_RST_ERROR_OUT);
            }

            ServiceResult<List<WMSStockRecord>> wServiceResult = wWMSService.WMS_QueryStockInfoByItemID(wLoginUser,
                    wSalesDeliveryItemID);

            if (StringUtils.isEmpty(wServiceResult.FaultCode)) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.Result, null);
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.FaultCode);
            }
        } catch (Exception ex) {
            logger.error(ex.toString());
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.toString());
        }
        return wResult;
    }
}
